a11y: Notify callers when an attributes set changes
authorEmmanuele Bassi <ebassi@gnome.org>
Wed, 5 Aug 2020 17:04:34 +0000 (18:04 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Tue, 25 Aug 2020 15:36:08 +0000 (16:36 +0100)
We can use that information inside the ATContext.

gtk/gtkaccessibleattributeset.c
gtk/gtkaccessibleattributesetprivate.h

index abdc0950ed85f552f7353ebacb50e86faf19c3e4..f49a9cf9112ca2c55cd974363777d588626bab0e 100644 (file)
@@ -114,13 +114,26 @@ gtk_accessible_attribute_set_unref (GtkAccessibleAttributeSet *self)
  *
  * If you want to remove @attribute from the set, use gtk_accessible_attribute_set_remove()
  * instead.
+ *
+ * Returns: %TRUE if the set was modified, and %FALSE otherwise
  */
-void
+gboolean
 gtk_accessible_attribute_set_add (GtkAccessibleAttributeSet *self,
                                   int                        attribute,
                                   GtkAccessibleValue        *value)
 {
-  g_return_if_fail (attribute >= 0 && attribute < self->n_attributes);
+  g_return_val_if_fail (attribute >= 0 && attribute < self->n_attributes, FALSE);
+
+  if (value != NULL)
+    {
+      if (gtk_accessible_value_equal (value, self->attribute_values[attribute]))
+        return FALSE;
+    }
+  else
+    {
+      if (!_gtk_bitmask_get (self->attributes_set, attribute))
+        return FALSE;
+    }
 
   g_clear_pointer (&(self->attribute_values[attribute]), gtk_accessible_value_unref);
 
@@ -130,18 +143,34 @@ gtk_accessible_attribute_set_add (GtkAccessibleAttributeSet *self,
     self->attribute_values[attribute] = (* self->default_func) (attribute);
 
   self->attributes_set = _gtk_bitmask_set (self->attributes_set, attribute, TRUE);
+
+  return TRUE;
 }
 
-void
+/*< private >
+ * gtk_accessible_attribute_set_remove:
+ * @self: a #GtkAccessibleAttributeSet
+ * @attribute: the attribute to be removed
+ *
+ * Resets the @attribute in the given #GtkAccessibleAttributeSet to its default value.
+ *
+ * Returns: %TRUE if the set was modified, and %FALSE otherwise
+ */
+gboolean
 gtk_accessible_attribute_set_remove (GtkAccessibleAttributeSet *self,
                                      int                        attribute)
 {
-  g_return_if_fail (attribute >= 0 && attribute < self->n_attributes);
+  g_return_val_if_fail (attribute >= 0 && attribute < self->n_attributes, FALSE);
+
+  if (!_gtk_bitmask_get (self->attributes_set, attribute))
+    return FALSE;
 
   g_clear_pointer (&(self->attribute_values[attribute]), gtk_accessible_value_unref);
 
   self->attribute_values[attribute] = (* self->default_func) (attribute);
   self->attributes_set = _gtk_bitmask_set (self->attributes_set, attribute, FALSE);
+
+  return TRUE;
 }
 
 gboolean
index 57a1e63e35ae4fd61c7bb0834fb29bf069430541..83694c7eded3ac708148b4b48ad76101c295a51e 100644 (file)
@@ -37,10 +37,10 @@ void                            gtk_accessible_attribute_set_unref
 
 gsize                           gtk_accessible_attribute_set_get_length         (GtkAccessibleAttributeSet  *self);
 
-void                            gtk_accessible_attribute_set_add                (GtkAccessibleAttributeSet  *self,
+gboolean                        gtk_accessible_attribute_set_add                (GtkAccessibleAttributeSet  *self,
                                                                                  int                         attribute,
                                                                                  GtkAccessibleValue         *value);
-void                            gtk_accessible_attribute_set_remove             (GtkAccessibleAttributeSet  *self,
+gboolean                        gtk_accessible_attribute_set_remove             (GtkAccessibleAttributeSet  *self,
                                                                                  int                         state);
 gboolean                        gtk_accessible_attribute_set_contains           (GtkAccessibleAttributeSet  *self,
                                                                                  int                         state);